var getHost = function(url) { 
        var host = "null";
        if(typeof url == "undefined"
                        || null == url)
                url = window.location.href;
        var regex = /.*\:\/\/([^\/]*).*/;
        var match = url.match(regex);
        if(typeof match != "undefined"
                        && null != match)
                host = match[1];
        return host;
}
//获得source 的值 保存到cookie  
var loc=getHost(document.location.href);
    var domain="365hls.com";
    if(loc.indexOf("zonezone.com")>0){
        domain="zonezone.com";
    }
     if(loc.indexOf("365hls.com")>0){
        domain="365hls.com";
    }
    
function addCookie(objName, objValue, objHours) { // 添加cookie
    
	var date1=new Date();
//	objName+=""+date1.getTime();
	var str = objName + "=" + escape(objValue);
	if (objHours > 0) { // 为时不设定过期时间，浏览器关闭时cookie自动消失
		var date = new Date();
		var ms = 24 * 30 * 3600 * 1000;
		date.setTime(date.getTime() + ms);
		str += "; expires=" + date.toGMTString();
	}
	document.cookie = str +"; path=/";	
}
function getUrlVars(url){

    var vars = [], hash;
    var hashes = url.slice(url.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
function setfrom() {
var arr=getUrlVars(document.location.href);
if (arr["source"]){
    addCookie("365hlssource", arr["source"],1);
}	
}

function setinsource() {
var arr=getUrlVars(document.location.href);
if (arr["insource"]){
    addCookie("insource", arr["insource"],1);
}	
}

var source="";
var keywords="";
var ref = document.referrer;
var stt=ref;
var code="utf-8";
function getreffer() {
   if (window.ActiveXObject){
       code="gbk";
   }	
   if (ref&&(ref.indexOf(domain)==-1||ref.indexOf(domain)>20)){
	if (ref != undefined && ref != "") {
            var arr=getUrlVars(ref);
            var source=getHost(ref);
		if (source.indexOf("www.baidu.com") == 0) { 
            			keywords=arr["wd"];
//                                code=arr["ie"];
            	}
		else	if (source.indexOf("www.google.com") == 0
                        ||source.indexOf("www.so.com") == 0
                        ||source.indexOf("www.bing.com") == 0
                        ||source.indexOf("www.youdao.com") == 0
                        ||source.indexOf("www.panguso.com") == 0
                        ||source.indexOf("m.so.com") == 0
                        ||source.indexOf("m.sm.cn") == 0
                        ||source.indexOf("easou.com") == 0
                        ||source.indexOf("so.360.cn")==0
                        ||source.indexOf("m.haosou.com")==0
                        ||source.indexOf("www.haosou.com")==0
                        ||source.indexOf("i.easou.com")==0
                        ||source.indexOf("www.chinaso.com")==0
                        ||source.indexOf("m.sj.sm.cn")==0
                        
                        ) {
            			keywords=arr["q"];    
//                                code=arr["ie"];
		}
		else if (source.indexOf("glb.uc.cn") == 0||ref.indexOf("wap.sogou.com") == 0) {
            			keywords=arr["keyword"];
//                                code=arr["utf-8"];
		}
                else if (source.indexOf("wap.soso.com") == 0) {
            			keywords=arr["key"];
//                                code=arr["utf-8"];
		}
                else if (source.indexOf("m.baidu.com") == 0||source.indexOf("wap.baidu.com") == 0) {
            			keywords=arr["word"];
//                                code=arr["utf-8"];
		}
                else if (source.indexOf("www.sogou.com") == 0||ref.indexOf("www.soso.com") == 0) {
            			keywords=arr["query"];
//                                code=arr["utf-8"];
		}else if (source.indexOf("cn.bing.com") == 0) {
            			keywords=arr["pq"];
//                                code=arr["utf-8"];
		}
	}        
	addCookie("365hlsfrom",source+"-----"+keywords+"-----"+stt+"-----"+code,1);
    }
}
function getplatform(){
    var arr=getUrlVars(document.location.href);
    if (arr["platform"]){
        addCookie("platform", arr["platform"],1);
    }   
}
getreffer();
setfrom();
getplatform();
setinsource();